package com.woniu.controller;

import com.woniu.entity.RbacManagerDTO;
import com.woniu.entity.RbacManager;
import com.woniu.entity.ResponseEntity;
import com.woniu.service.RbacManagerService;
import org.apache.shiro.authz.annotation.Logical;
import org.apache.shiro.authz.annotation.RequiresRoles;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * @author:陈涵
 * @Do:用户管理的接口
 * @date: 2022/9/1 23:08
 */
@RestController
@RequestMapping("/rbacManager")
@RequiresRoles(logical = Logical.OR,value={"admin","nomal"})
@CrossOrigin
public class RbacManagerController {

    @Autowired
    RbacManagerService rbacManagerService;

    @GetMapping("/findAll/{currentPage}/{pageSize}")
    public ResponseEntity findAll(@PathVariable("currentPage") int currentPage,@PathVariable("pageSize") int pageSize){
        return rbacManagerService.findAll(currentPage,pageSize);
    }
    @DeleteMapping("/deleteOne/{id}")
    public ResponseEntity deleteOne(@PathVariable("id") int id){
        return rbacManagerService.deleteOne(id);
    }
    @RequestMapping("/addOne")
    public ResponseEntity addOne(@RequestBody RbacManagerDTO rbacManager){
        return rbacManagerService.addOne(rbacManager);
    }
    @RequestMapping("/editOne")
    public ResponseEntity editOne(@RequestBody RbacManager rbacManager){
        return rbacManagerService.editOne(rbacManager);
    }
    @GetMapping("/editType/{id}/{status}")
    public ResponseEntity editOne(@PathVariable int id,@PathVariable String status){
        return rbacManagerService.editType(id,status);
    }
    @GetMapping("/initPwd/{id}")
    public ResponseEntity initPwd(@PathVariable int id){
        return rbacManagerService.initPwd(id);
    }

    @PostMapping("/updateRole")
    public ResponseEntity updateRole(@RequestBody RbacManagerDTO rbacManagerDTO){
        return rbacManagerService.updateRole(rbacManagerDTO);
    }
}
